{% extends 'new-layout/layout.html' %}
{% import 'libs/libs.html' as libs %}
{% import 'libs/const.html' as const %}

{% block title_nav %}
<li><a href="{{ request.cookies.get('goback_url', '/user/') }}">用户列表</a></li>
{% endblock %}

{% block body %}
<div class="row">
    <div class="col-lg-4 col-md-4 col-xs-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">基本信息</div>
            <div class="ibox-content">
                <table class="table table-bordered">
                    <tr><th>uid</th><td>{{ user.uid }}</td></tr>
                    <tr><th>手机号码</th><td>{{ user.mobile }}</td></tr>
                    <tr><th>头像</th><td><img src="{{ user.avatar_small }}" style="width:50px;"></td></tr>
                    <tr><th>妮称</th><td>{{ user.nickname }}</td></tr>
                    <tr><th>性别</th><td>{{ const.GENDER.get(user.gender, 0) }}</td></tr>
                    <tr><th>出生年</th><td>{{ user.birth_year }}</td></tr>
                    <tr><th>真实姓名</th><td>{{ user.realname }}</td></tr>
                    <tr><th>身份证号码</th><td>{{ user.id_no }}</td></tr>
                    <tr><th>地址</th><td>{{ user.province + ' ' + user.city + ' ' + user.district }}</td></tr>

                    <tr><th>注册时间</th><td>{{ user.regtime|format_timestamp }}</td></tr>
                    <tr><th>注册ip</th><td>{{ user.regip }}</td></tr>
                    <tr><th>最后访问时间</th><td>{{ user.lastvisit }}</td></tr>
                    <tr><th>最后访问IP</th><td>{{ user.lastip }}</td></tr>
                    <tr><th>经度</th><td>{{ user.jingdu }}</td></tr>
                    <tr><th>纬度</th><td>{{ user.weidu }}</td></tr>

                    <tr><th>手机厂商</th><td>{{ user.vendor }}</td></tr>
                    <tr><th>手机型号</th><td>{{ user.device }}</td></tr>
                    <tr><th>os</th><td>{{ user.os }}</td></tr>
                    <tr><th>系统版本号</th><td>{{ user.osver }}</td></tr>
                    <tr><th>客户端版本号</th><td>{{ user.version }}</td></tr>

                </table>
            </div>
        </div>
    </div>

    <div class="col-lg-4 col-md-4 col-xs-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">身份证</div>
            <div class="ibox-content">
            {% if ura %}
                <table class="table table-bordered">
                    <tr><th>申请时间：</th><td>{{ ura.apply_time|format_timestamp }}</td></tr>
                    <tr><th>姓名：</th><td>{{ ura.realname }}</td></tr>
                    <tr><th>身份证号码：</th><td>{{ ura.id_no }}</td></tr>
                    <tr>
                        <th>正面图：</th>
                        <td>
                            {% if ura.id_pic_front %}
                            <a target="_blank" href="{{ ura.id_pic_front }}"><img src="{{ ura.id_pic_front }}@100Q_100w" style="width:100px;"></a>
                            {% else %}--
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <th>背面图：</th>
                        <td>
                            {% if ura.id_pic_back %}
                            <a target="_blank" href="{{ ura.id_pic_back }}"><img src="{{ ura.id_pic_back }}@100Q_100w" style="width:100px;"></a>
                            {% else %}--
                            {% endif %}
                        </td>
                    </tr>
                    <tr><th>审核时间：</th><td>{{ ura.check_time|format_timestamp }}</td></tr>
                    <tr><th>审核人：</th><td>{{ ura.checker }}</td></tr>
                    <tr><th>操作/状态：</th><td>
                        {% if ura.status in (2,3) %}
                            {{ const.REALNAME_STATUS.get(ura.status, 0) }}
                        {% else %}
                            <a href="javascript:;" onclick="apply(this, {{ ura.id }}, 2);" class="btn btn-sm btn-primary">审核通过</a>
                            <a href="javascript:;" class="btn btn-sm btn-danger" data-toggle="modal" data-target="#realname-modal" data-id="{{ ura.id }}">拒绝通过</a>
                        {% endif %}
                    </td></tr>
                </table>
            {% endif %}
            </div>
        </div>
    </div>

    <div class="col-lg-4 col-md-4 col-xs-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">关注类目</div>
            <div class="ibox-content">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <td>序号</td>
                            <td>名称</td>
                            <td>时间</td>
                        </tr>
                    </thead>
                    <tbody>
                    {% for fc in follow_cat_list %}
                        <tr>
                            <td>{{ loop.index }}</td>
                            <td>{{ fc.cat_name }}</td>
                            <td>{{ fc.add_time|format_timestamp }}</td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <div class="col-lg-4 col-md-4 col-xs-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">相册</div>
            <div class="ibox-content">
                <div class="row">
                {% for ui in ui_list %}
                    <div class="file-box">
                        <div class="file">
                            <a target="_blank" href="{{ ui.img_original }}">
                                <span class="corner"></span>
                                <div class="image">
                                    <img src="{{ ui.img_thumb }}" class="img-responsive" alt="image">
                                </div>
                                <div class="file-name">
                                    <small>{{ ui.add_time|get_social_time }}</small>
                                    <br/>
                                    {% if ui.type == 2 and ui.status == 1 %}
                                        <a href="javascript:;" onclick="cert_check(this, {{ ui.id }}, 2);">审核通过</a>&nbsp;
                                        <a href="javascript:;" onclick="cert_check(this, {{ ui.id }}, 3);">审核不通过</a>
                                    {% else %}
                                        {% if ui.is_delete == 0 %}
                                            <a href="javascript:;" onclick="delete_image(this, {{ ui.id }}, 1);">删除</a>
                                        {% else %}
                                            <a href="javascript:;" onclick="delete_image(this, {{ ui.id }}, 0);">恢复</a>
                                        {% endif %}

                                    {% endif %}
                                </div>
                            </a>
                        </div>
                    </div>
                {% endfor %}
                </div>
            </div>
        </div>
    </div>

    <div class="col-lg-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">教练审核 ==> 满足7个基本资料 && 实名认证通过 && 资格认证通过</div>
            <div class="ibox-content">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <td>头像</td>
                            <td>妮称</td>
                            <td>性别</td>
                            <td>出生年</td>
                            <td>手机号码</td>
                            <td class="col-lg-4">个人简介</td>
                            <td class="col-lg-2">执教区域</td>
                            <td>通过实名认证</td>
                            <td>通过资格认证</td>
                            <td>状态</td>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><img src="{{ user.avatar_small }}" style="width:50px;"></td>
                            <td>{{ user.nickname }}</td>
                            <td>{{ const.GENDER.get(user.gender, 0) }}</td>
                            <td>{{ user.birth_year }}</td>
                            <td>{{ user.mobile }}</td>
                            <td>{{ user.signature }}</td>
                            <td>{{ region_names }}</td>
                            <td>{{ const.YES_OR_NO.get(user.is_real, 0)|safe }}</td>
                            <td>{{ const.YES_OR_NO.get(user.is_cert, 0)|safe }}</td>
                            <td>{{ const.REALNAME_STATUS.get(user.teacher_status, 0) }}</td>
                        </tr>
                        {% if user.teacher_status == 1 %}
                        <tr>
                            <td colspan="10" id="teacher_apply_td">
                                <button onclick="update_to_teacher(this, {{ user.uid }}, 2);" class="btn btn-sm btn-primary">升级成为老师</button>
                                <button class="btn btn-sm btn-danger" data-toggle="modal" data-target="#teacher-modal">拒绝通过</button>
                            </td>
                        </tr>
                        {% endif %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>

</div>

{% endblock %}


{% block footer %}
<div class="modal fade" id="realname-modal" role="dialog">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="exampleModalLabel">审核身份证</h4>
            </div>
            <div class="modal-body">
                <form>
                    <div class="form-group">
                        <label class="control-label">拒绝原因：</label>
                        <div class="controls">
                            <textarea name="desc" class="col-lg-12" id="reject_desc"></textarea>
                        </div>
                    </div>
                    <input type="hidden" id="apply_id" value="">
                    <input type="hidden" id="reject_status" value="">
                </form>
            </div>
            <div class="modal-footer" style="margin-top: 20px;">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-danger" onclick="javascript:reject();">拒绝通过</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="teacher-modal" role="dialog">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">教练审核</h4>
            </div>
            <div class="modal-body">
                <form>
                    <div class="form-group">
                        <label class="control-label">拒绝原因：</label>
                        <div class="controls">
                            <textarea name="desc" class="col-lg-12" id="teacher_desc"></textarea>
                        </div>
                    </div>
                    <input type="hidden" id="uid" value="{{ user.uid }}">
                    <input type="hidden" id="teacher_reject_status" value="">
                </form>
            </div>
            <div class="modal-footer" style="margin-top: 20px;">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-danger" onclick="javascript:teacher_reject();">拒绝通过</button>
            </div>
        </div>
    </div>
</div>


<script src="/static/set-of-styles/default/js/modal.js"></script>
<script type="text/javascript">
function apply(adom, id, status) {
    $.get('/user/realname/apply', {'id':id, 'status':status}, function(data) {
        if (data != 'ok') {
            alert(data);
            return;
        }

        var $a = $(adom);
        var $parent_td = $a.parent();
        var icon = 'fa-check';
        if (status == 3) {
            icon = 'fa-times';
        }

        $parent_td.html('<i class="fa ' + icon + '" style="color:red; font-size:24px;"></i>');

    });
}

function delete_image(adom, id, is_delete) {
    $.get('/user/image/delete/'+id, {'is_delete':is_delete}, function(data) {
        if (data != 'ok') {
            alert(data);
            return;
        }

        var $a = $(adom);
        var $file_box = $a.parents('.file-box')[0];
        $file_box.remove();


    });
}

function cert_check(adom, id, status) {
    $.get('/user/cert/check', {'id':id, 'status':status}, function(data) {
        if (data != 'ok') {
            alert(data);
            return;
        }

        var $a = $(adom);
        var icon = 'fa-check';
        if (status == 3) {
            icon = 'fa-times';
        }

        $a.html('<i class="fa ' + icon + '" style="color:red; font-size:24px;"></i>');
        if (status == 2) {
            $a.next().remove();
        } else {
            $a.prev().remove();
        }

    });
}

/**
 * 老师审核
 */
function update_to_teacher(dom, uid, status) {
    $.get('/user/update_to_teacher', {'uid':uid, 'status':status}, function(data) {
        if (data != 'ok') {
            alert(data);
            return;
        }

        $btn = $(dom);
        var $parent_td = $btn.parent();
        var icon = 'fa-check';
        if (status == 3) {
            icon = 'fa-times';
        }

        $parent_td.html('<i class="fa ' + icon + '" style="color:red; font-size:24px;"></i>');
    });
}


// 显示 realname-modal
$("#realname-modal").on("show.bs.modal", function (e) {
    var $invoker = $(e.relatedTarget);
    var data_id = $invoker.attr('data-id');
    $('#apply_id').val(data_id);
    $('#reject_status').val('');
});

// 隐藏 realname-modal
$('#realname-modal').on('hide.bs.modal',  function (e) {
    var reject_status = $('#reject_status').val();
    if (reject_status == '3') {
        var apply_id = $('#apply_id').val();
        var $a = $('a[data-id="' + apply_id + '"]');
        var $parent_td = $a.parent();
        $parent_td.html('<i class="fa fa-times" style="color:red; font-size:24px;"></i>');
    } 

});

// 实名认证，拒绝通过
function reject() {
    var reject_desc = $('#reject_desc').val();
    var apply_id = $('#apply_id').val();

    $.get('/user/realname/apply', {'id':apply_id, 'reject_desc':reject_desc, 'status':'3'}, function(data) {
        if (data != 'ok') {
            alert(data);
            return;
        }

    });

    $('#reject_status').val('3');
    $('#realname-modal').modal('hide');

}

// 显示 teacher-modal
$("#teacher-modal").on("show.bs.modal", function (e) {
    $('#teacher_reject_status').val('');
});

// 隐藏 teacher-modal
$('#teacher-modal').on('hide.bs.modal',  function (e) {
    var teacher_reject_status = $('#teacher_reject_status').val();
    if (teacher_reject_status == '3') {
        var $teacher_apply_td = $('#teacher_apply_td');
        $teacher_apply_td.html('<i class="fa fa-times" style="color:red; font-size:24px;"></i>');
    } 

});

// 教练认证，拒绝通过
function teacher_reject() {
    var teacher_desc = $('#teacher_desc').val();
    var uid = $('#uid').val();

    $.get('/user/update_to_teacher', {'uid':uid, 'status':'3', 'reject_desc':teacher_desc}, function(data) {
        if (data != 'ok') {
            alert(data);
            return;
        }
    });

    $('#teacher_reject_status').val('3');
    $('#teacher-modal').modal('hide');

}

</script>
{% endblock %}